package cn.jd.basic.controller;

import cn.jd.basic.dto.*;
import cn.jd.basic.service.LoginService;
import cn.jd.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private LoginService loginService;
    /**
     * 用户数据保存
     * wechat/binder
     */
    @PostMapping ("/wechat/binder")
    public AjaxResult binder(@RequestBody WXLoginDto dto) {
        Map<String,Object> map=loginService.binder(dto);
        return AjaxResult.me().success(map);
    }

    /**
     * 微信扫码登录
     * /login/wechat
     * @param dto
     * @return
     */
    @PostMapping ("/wechat")
    public AjaxResult wechat(@RequestBody WechatLoginDto dto) {
        System.out.println(12);
        AjaxResult ajaxResult = loginService.wechatLogin(dto);
        System.out.println(ajaxResult);
        return ajaxResult;
    }

    /**
     * 普通方式登录
     * @param
     * @return
     */
    @PostMapping("/account")
    public AjaxResult accountLogin(@RequestBody @Valid LoginAccountDto dto) {
        System.out.println(123);
        Map<String,Object> map=loginService.accountLogin(dto);
        return AjaxResult.me().success(map);
    }
    /**
     * 手机验证码登录
     */
    @PostMapping("/accountuser")
    public AjaxResult accountuser(@RequestBody @Valid AccountPhoneDto dto) {

        Map<String,Object> map=loginService.accountuser(dto);
        return AjaxResult.me().success(map);
    }
}
